<template>
  <div>
    <h2 style="text-align: center;">管理员-投资列表</h2>
    <table>
      <tr>
        <td>
          投资名称<input type="text" v-model="chaxun.tname">
          <input type="button" value="查询" @click="xian1">
        </td>
      </tr>
    </table>
    <table class="table table-bordered ">
      <thead>
        <tr>
          <td>投资ID</td>
          <td>投资项目名称</td>
          <td>总额度</td>
          <td>已投金额</td>
          <td>剩余额度</td>
          <td>投资次数</td>
          <td>操作</td>
        </tr>
      </thead>
      <tbody v-for="em in info" :key="em.tid">
        <tr>
          <td>{{ em.tid }}</td>
          <td>{{ em.tname }}</td>
          <td>{{ em.pricecount }}</td>
          <td>{{ em.priceyitou }}</td>
          <td>{{ em.priceshengyu }}</td>
          <td>{{ em.tnum }}</td>
          <td><input type="button" value="删除" @click="shanchu(em.tid)"></td>
        </tr>
      </tbody>
    </table>
    一共<span>{{ chaxun.totalcount }}</span>条数据
    一共<span>{{ chaxun.pagecount }}</span>页
    当前第<span>{{ chaxun.pageindex }}</span>页
    每页显示<span>{{ chaxun.pagesize }}</span>条
      <a href="#" @click="page(1)">首页</a>
      <a href="#" @click="page(chaxun.pageindex-1)">上一页</a>
      <a href="#" @click="page(chaxun.pageindex+1)">下一页</a>
      <a href="#" @click="page(chaxun.pagecount)">尾页</a>
      <select v-model="chaxun.pagesize" @change="dd">
    <option value="3">3条/页</option>
    <option value="4">4条/页</option>
    <option value="5">5条/页</option>
    <option value="6">6条/页</option>
  </select>
  <input type="text" v-model="chaxun.pageindex">
  <input type="button" value="跳转" @click="page(chaxun.pageindex)">
  </div>
</template>


<script setup lang="ts">
import { ref, onMounted } from 'vue';
import axios from 'axios';
import {useRouter} from 'vue-router';
let router=useRouter();
const info=ref([{
  tid:0,
  tname:"",
  pricecount:"",
  priceyitou:"",
  priceshengyu:"",
  tnum:"",
}])
const chaxun=ref({
  tname:"",
  pageindex:1,
  pagesize:2,
  pagecount:0,
  totalcount:0,
})
const page=(i:any)=>{
if(i>=1&&i<=chaxun.value.pagecount)
{
  chaxun.value.pageindex=i;
  xian();
}
}
const dd=()=>{
  xian();
}
//生命周期
onMounted(()=>{
  xian();
})
//显示
const xian=()=>{
  axios({
    url:"http://localhost:8322/api/User/usertouzishow",
    method:"get",
    params:chaxun.value
  }).then(function(res){
    info.value=res.data.b;
    chaxun.value.pagecount=res.data.pagecount;
    chaxun.value.totalcount=res.data.totalcount;
    console.log(res.data.data);
  }).catch(function(err){
    console.log(err);
  })
}
//查询
const xian1=()=>{
  xian();
}


//逻辑删除
const shanchu=(tid:any)=>{
  if(confirm("确定删除吗？"))
  {
    axios({
    url:"http://localhost:8322/api/User/delete",
    method:"get",
    params:{
      tid:tid
    }
  }).then((res)=>{
    if(res.data==3)
    {
      alert("当前有人投资无法删除");
    }
  else  if(res.data>0)
    {
        alert("删除成功");
        xian();
    }
    else
    {
      alert("删除失败");
    }
  
  }).catch((err)=>{
    console.log(err);
  })
  }
}
</script>

<style scoped>

</style>